<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<link rel="Start" href="index.html">
<link rel="previous" href="Dtd.html">
<link rel="next" href="XmlParser.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Dtd" rel="Chapter" href="Dtd.html">
<link title="Xml" rel="Chapter" href="Xml.html">
<link title="XmlParser" rel="Chapter" href="XmlParser.html"><link title="Xml Data Structure" rel="Section" href="#6_XmlDataStructure">
<link title="Xml Parsing" rel="Section" href="#6_XmlParsing">
<link title="Xml Exceptions" rel="Section" href="#exc">
<link title="Xml Functions" rel="Section" href="#6_XmlFunctions">
<link title="Xml Printing" rel="Section" href="#6_XmlPrinting">
<title>Xml</title>
</head>
<body>
<div class="navbar"><a href="Dtd.html">Previous</a>
&nbsp;<a href="index.html">Up</a>
&nbsp;<a href="XmlParser.html">Next</a>
</div>
<center><h1>Module <a href="type_Xml.html">Xml</a></h1></center>
<br>
<pre><span class="keyword">module</span> Xml: <code class="code">sig</code> <a href="Xml.html">..</a> <code class="code">end</code></pre>Xml Light
<p>

  Xml Light is a minimal Xml parser &amp; printer for OCaml.
  It provide few functions to parse a basic Xml document into
  an OCaml data structure and to print back the data structures
  to an Xml document.
<p>

  Xml Light has also support for <b>DTD</b> (Document Type Definition).
<p>

  <i>(c)Copyright 2002-2003 Nicolas Cannasse</i><br>
<hr width="100%">
<br>
<a name="6_XmlDataStructure"></a>
<h6>Xml Data Structure</h6><br>
<br><code><span class="keyword">type</span> <a name="TYPExml"></a><code class="type"></code>xml = </code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">Element</span> <span class="keyword">of</span> <code class="type">(string * (string * string) list * <a href="Xml.html#TYPExml">xml</a> list)</code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">PCData</span> <span class="keyword">of</span> <code class="type">string</code></code></td>

</tr></table>

<div class="info">
An Xml node is either
	<code class="code">Element (tag-name, attributes, children)</code> or <code class="code">PCData text</code><br>
</div>

<br>
<a name="6_XmlParsing"></a>
<h6>Xml Parsing</h6><br>
<br>
For easily parsing an Xml data source into an xml data structure,
	you can use theses functions. But if you want advanced parsing usage,
	please look at the <a href="XmlParser.html"><code class="code">XmlParser</code></a> module.
	All the parsing functions can raise some exceptions, see the
	<a href="#exc">Exceptions</a> section for more informations.<br>
<pre><span class="keyword">val</span> <a name="VALparse_file"></a>parse_file : <code class="type">string -> <a href="Xml.html#TYPExml">xml</a></code></pre><div class="info">
Parse the named file into an Xml data structure.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALparse_in"></a>parse_in : <code class="type">Pervasives.in_channel -> <a href="Xml.html#TYPExml">xml</a></code></pre><div class="info">
Read the content of the in_channel and parse it into an Xml data
 structure.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALparse_string"></a>parse_string : <code class="type">string -> <a href="Xml.html#TYPExml">xml</a></code></pre><div class="info">
Parse the string containing an Xml document into an Xml data
 structure.<br>
</div>
<br>
<a name="exc"></a>
<h6>Xml Exceptions</h6><br>
<br>
Several exceptions can be raised when parsing an Xml document : <ul>
<li><a href="Xml.html#EXCEPTIONError"><code class="code">Xml.Error</code></a> is raised when an xml parsing error occurs. the
		<a href="Xml.html#VALerror_msg"><code class="code">Xml.error_msg</code></a> tells you which error occured during parsing
		and the <a href="Xml.html#TYPEerror_pos"><code class="code">Xml.error_pos</code></a> can be used to retreive the document
		location where the error occured at.</li>
<li><a href="Xml.html#EXCEPTIONFile_not_found"><code class="code">Xml.File_not_found</code></a> is raised when and error occured while
		opening a file with the <a href="Xml.html#VALparse_file"><code class="code">Xml.parse_file</code></a> function or when a
		DTD file declared by the Xml document is not found <i>(see the
		<a href="XmlParser.html"><code class="code">XmlParser</code></a> module for more informations on how to handle the
		DTD file loading)</i>.</li>
</ul>

	If the Xml document is containing a DTD, then some other exceptions
	can be raised, see the module <a href="Dtd.html"><code class="code">Dtd</code></a> for more informations.<br>
<pre><span class="keyword">type</span> <a name="TYPEerror_pos"></a><code class="type"></code>error_pos </pre>

<br><code><span class="keyword">type</span> <a name="TYPEerror_msg"></a><code class="type"></code>error_msg = </code><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">UnterminatedComment</span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">UnterminatedString</span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">UnterminatedEntity</span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">IdentExpected</span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">CloseExpected</span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">NodeExpected</span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">AttributeNameExpected</span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">AttributeValueExpected</span></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">EndOfTagExpected</span> <span class="keyword">of</span> <code class="type">string</code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span class="constructor">EOFExpected</span></code></td>

</tr></table>


<pre><span class="keyword">type</span> <a name="TYPEerror"></a><code class="type"></code>error = <code class="type"><a href="Xml.html#TYPEerror_msg">error_msg</a> * <a href="Xml.html#TYPEerror_pos">error_pos</a></code> </pre>

<pre><span class="keyword">exception</span> <a name="EXCEPTIONError"></a>Error <span class="keyword">of</span> <code class="type"><a href="Xml.html#TYPEerror">error</a></code></pre>
<pre><span class="keyword">exception</span> <a name="EXCEPTIONFile_not_found"></a>File_not_found <span class="keyword">of</span> <code class="type">string</code></pre>
<pre><span class="keyword">val</span> <a name="VALerror"></a>error : <code class="type"><a href="Xml.html#TYPEerror">error</a> -> string</code></pre><div class="info">
Get a full error message from an Xml error.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALerror_msg"></a>error_msg : <code class="type"><a href="Xml.html#TYPEerror_msg">error_msg</a> -> string</code></pre><div class="info">
Get the Xml error message as a string.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALline"></a>line : <code class="type"><a href="Xml.html#TYPEerror_pos">error_pos</a> -> int</code></pre><div class="info">
Get the line the error occured at.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALrange"></a>range : <code class="type"><a href="Xml.html#TYPEerror_pos">error_pos</a> -> int * int</code></pre><div class="info">
Get the relative character range (in current line) the error occured at.<br>
</div>
<pre><span class="keyword">val</span> <a name="VALabs_range"></a>abs_range : <code class="type"><a href="Xml.html#TYPEerror_pos">error_pos</a> -> int * int</code></pre><div class="info">
Get the absolute character range the error occured at.<br>
</div>
<br>
<a name="6_XmlFunctions"></a>
<h6>Xml Functions</h6><br>
<pre><span class="keyword">exception</span> <a name="EXCEPTIONNot_element"></a>Not_element <span class="keyword">of</span> <code class="type"><a href="Xml.html#TYPExml">xml</a></code></pre>
<pre><span class="keyword">exception</span> <a name="EXCEPTIONNot_pcdata"></a>Not_pcdata <span class="keyword">of</span> <code class="type"><a href="Xml.html#TYPExml">xml</a></code></pre>
<pre><span class="keyword">exception</span> <a name="EXCEPTIONNo_attribute"></a>No_attribute <span class="keyword">of</span> <code class="type">string</code></pre>
<pre><span class="keyword">val</span> <a name="VALtag"></a>tag : <code class="type"><a href="Xml.html#TYPExml">xml</a> -> string</code></pre><div class="info">
<code class="code">tag xdata</code> returns the tag value of the xml node.
 Raise <a href="Xml.html#EXCEPTIONNot_element"><code class="code">Xml.Not_element</code></a> if the xml is not an element<br>
</div>
<pre><span class="keyword">val</span> <a name="VALpcdata"></a>pcdata : <code class="type"><a href="Xml.html#TYPExml">xml</a> -> string</code></pre><div class="info">
<code class="code">pcdata xdata</code> returns the PCData value of the xml node.
 Raise <a href="Xml.html#EXCEPTIONNot_pcdata"><code class="code">Xml.Not_pcdata</code></a> if the xml is not a PCData<br>
</div>
<pre><span class="keyword">val</span> <a name="VALattribs"></a>attribs : <code class="type"><a href="Xml.html#TYPExml">xml</a> -> (string * string) list</code></pre><div class="info">
<code class="code">attribs xdata</code> returns the attribute list of the xml node.
 First string if the attribute name, second string is attribute value.
 Raise <a href="Xml.html#EXCEPTIONNot_element"><code class="code">Xml.Not_element</code></a> if the xml is not an element<br>
</div>
<pre><span class="keyword">val</span> <a name="VALattrib"></a>attrib : <code class="type"><a href="Xml.html#TYPExml">xml</a> -> string -> string</code></pre><div class="info">
<code class="code">attrib xdata "href"</code> returns the value of the <code class="code">"href"</code>
 attribute of the xml node (attribute matching is case-insensitive).
 Raise <a href="Xml.html#EXCEPTIONNo_attribute"><code class="code">Xml.No_attribute</code></a> if the attribute does not exists in the node's
 attribute list 
 Raise <a href="Xml.html#EXCEPTIONNot_element"><code class="code">Xml.Not_element</code></a> if the xml is not an element<br>
</div>
<pre><span class="keyword">val</span> <a name="VALchildren"></a>children : <code class="type"><a href="Xml.html#TYPExml">xml</a> -> <a href="Xml.html#TYPExml">xml</a> list</code></pre><div class="info">
<code class="code">children xdata</code> returns the children list of the xml node
 Raise <a href="Xml.html#EXCEPTIONNot_element"><code class="code">Xml.Not_element</code></a> if the xml is not an element<br>
</div>
<pre><span class="keyword">val</span> <a name="VALiter"></a>iter : <code class="type">(<a href="Xml.html#TYPExml">xml</a> -> unit) -> <a href="Xml.html#TYPExml">xml</a> -> unit</code></pre><div class="info">
<code class="code">iter f xdata</code> calls f on all children of the xml node.
 Raise <a href="Xml.html#EXCEPTIONNot_element"><code class="code">Xml.Not_element</code></a> if the xml is not an element<br>
</div>
<pre><span class="keyword">val</span> <a name="VALmap"></a>map : <code class="type">(<a href="Xml.html#TYPExml">xml</a> -> 'a) -> <a href="Xml.html#TYPExml">xml</a> -> 'a list</code></pre><div class="info">
<code class="code">map f xdata</code> is equivalent to <code class="code">List.map f (Xml.children xdata)</code>
 Raise <a href="Xml.html#EXCEPTIONNot_element"><code class="code">Xml.Not_element</code></a> if the xml is not an element<br>
</div>
<pre><span class="keyword">val</span> <a name="VALfold"></a>fold : <code class="type">('a -> <a href="Xml.html#TYPExml">xml</a> -> 'a) -> 'a -> <a href="Xml.html#TYPExml">xml</a> -> 'a</code></pre><div class="info">
<code class="code">fold f init xdata</code> is equivalent to
 <code class="code">List.fold_left f init (Xml.children xdata)</code>
 Raise <a href="Xml.html#EXCEPTIONNot_element"><code class="code">Xml.Not_element</code></a> if the xml is not an element<br>
</div>
<br>
<a name="6_XmlPrinting"></a>
<h6>Xml Printing</h6><br>
<pre><span class="keyword">val</span> <a name="VALto_string"></a>to_string : <code class="type"><a href="Xml.html#TYPExml">xml</a> -> string</code></pre><div class="info">
Print the xml data structure into a compact xml string (without
 any user-readable formating ).<br>
</div>
<pre><span class="keyword">val</span> <a name="VALto_string_fmt"></a>to_string_fmt : <code class="type"><a href="Xml.html#TYPExml">xml</a> -> string</code></pre><div class="info">
Print the xml data structure into an user-readable string with
 tabs and lines break between different nodes.<br>
</div>
</body></html>